// component/guessLike/guessLike.js
var configUrl = require('../../../config/config')  //引入配置接口文件
let leftHeight = 0, rightHeight = 0; //分别定义左右两边的高度
let query;
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type: Object,
      // 数据类型
      value:{}
      // 数据值
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl:getApp().globalData.imgUrl,
    list: [],
    leftList: [],
    rightList: []
  },
  attached: function(){
    this.data.list = this.properties.data.pmsProductTableDTO.solrProductDtos.records
    this.isLeft()
    // let addrCode = wx.getStorageSync('addrCode')
    // let pricePstCode = addrCode.pricePstCode
    // this.getGuessYouLike(pricePstCode)
  }, // 组件挂载之前执行
  ready: function() {
  }, // 组件挂载后执行
  /**
   * 组件的方法列表
   */
  methods: {
    goodsInfo(option) {
      // this.getLogin((re)=>{
      //   if(re){
        let skuid = option.currentTarget.dataset.skuid
        wx.navigateTo({
          url: '/packageShop/pages/goodsInfo/goodsInfo?id=' + skuid,
        })
    //   }
    // })
   },
    async isLeft() {
      const { list, leftList, rightList } = this.data;
      query = wx.createSelectorQuery();
      for (const item of list) {
       leftHeight <= rightHeight ? leftList.push(item) : rightList.push(item); //判断两边高度，来觉得添加到那边
       await this.getBoxHeight(leftList, rightList);
      }
     },
     getBoxHeight(leftList, rightList) { //获取左右两边高度
      return new Promise((resolve, reject) => {
       this.setData({ leftList, rightList }, () => {
        const query = wx.createSelectorQuery().in(this)
        query.select('#left').boundingClientRect();
        query.select('#right').boundingClientRect();
        query.exec((res) => {
         leftHeight = res[0].height; //获取左边列表的高度
         rightHeight = res[1].height; //获取右边列表的高度
         resolve();
        });
       });
      })
     }
  }
})
